package cn.com.hatech.blog.module.admin.attach.controller;

import cn.com.hatech.blog.common.constant.Types;
import cn.com.hatech.blog.common.constant.WebConst;
import cn.com.hatech.blog.common.controller.BaseController;
import cn.com.hatech.blog.common.utils.Commons;
import cn.com.hatech.blog.module.admin.attach.entity.Attach;
import cn.com.hatech.blog.module.admin.attach.service.IAttachService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @projectName: hatech-blog
 * @package: cn.com.hatech.blog.module.admin.controller
 * @className: AttachController
 * @author: xuruikai
 * @description: 附件管理控制器
 * @date: 2020/1/11 14:27
 * @version: 1.0
 */
@Controller
@RequestMapping("admin/attach")
@Slf4j
public class AttachPageController extends BaseController {

    @Resource
    private IAttachService attachService;

    /**
     * 附件页面
     *
     * @param request
     * @param page
     * @param limit
     * @return
     */
    @GetMapping(value = "")
    public String index(HttpServletRequest request, @RequestParam(value = "page", defaultValue = "1") int page,
                        @RequestParam(value = "limit", defaultValue = "12") int limit) {
        IPage<Attach> attachPaginator = attachService.getAttaches(page, limit);
        request.setAttribute("attaches", attachPaginator);
        request.setAttribute(Types.ATTACH_URL.getType(), Commons.siteOption(Types.ATTACH_URL.getType(), Commons.siteUrl()));
        request.setAttribute("max_file_size", WebConst.MAX_FILE_SIZE / 1024);
        return "admin/attach/attach";
    }

}
